//
//  HJChatMessageTransferCell.m
//  KaiChat
//
//  Created by lx on 2024/1/24.
//

#import "HJChatMessageTransferCell.h"
#import "HJChatMessageModel.h"

@interface HJChatMessageTransferCell()

@property (nonatomic, weak) UILabel *acountLabel;
@property (nonatomic, weak) UILabel *stateLabel;
@property (nonatomic, weak) UIImageView *logoView;
@property (nonatomic, weak) UIImageView *coinIconView;
@property (nonatomic, weak) UIView *lineView;

@end


@implementation HJChatMessageTransferCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
 
        UILabel *acountLabel = [UILabel lableWithSuperView:self.bubbleView font:UIFontMake(13) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentLeft];
        
        UILabel *stateLabel = [UILabel lableWithSuperView:self.bubbleView font:UIFontMake(10) color:[UIColor.whiteColor colorWithAlphaComponent:0.5] title:nil textAlignment:NSTextAlignmentLeft];
        
        UIImageView *coinIconView = [UIImageView addToView:self.bubbleView];
        coinIconView.image = [UIImage imageNamed:@"USDT_icon"];
        
        UIImageView *logoView = [UIImageView addToView:self.bubbleView];
        logoView.image = [UIImage imageNamed:@"transfer_logo"];
        
        UIView *lineView = [UIView addToView:self.bubbleView];
        lineView.backgroundColor = UIColor.tj_8B6EFEColor;
        
        _coinIconView = coinIconView;
        _acountLabel = acountLabel;
        _logoView = logoView;
        _stateLabel = stateLabel;
        _lineView = lineView;

    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
 
    
    CGSize contentSize = self.messageLayout.containerViewRect.size;
    _logoView.frame = CGRectMake(contentSize.width - 42, 0, 42, 42);
    _coinIconView.frame = CGRectMake(10, 10, 30, 30);
    _acountLabel.frame = CGRectMake(_coinIconView.tj_MaxX + 8, _coinIconView.tj_y, contentSize.width - (_coinIconView.tj_MaxX + 8 + 10), _coinIconView.tj_height);
    _stateLabel.frame = CGRectMake(10, contentSize.height - 20, contentSize.width - 10, 20);
    _lineView.frame = CGRectMake(0, contentSize.height - 21, contentSize.width, lineHeight);
}

- (void)setMessageLayout:(HJChatMessageLayout *)messageLayout {
    [super setMessageLayout:messageLayout];
    
    _acountLabel.text = [NSString stringWithFormat:@"%@%@", Dividing_powl(messageLayout.messageModel.amount, 10, 6), messageLayout.messageModel.payCoin];
    
    
    if (messageLayout.messageModel.isReadDetail) {
        if (self.bubbleView.alpha != 0.5) {
            self.bubbleView.alpha = 0.5;
        }
    } else {
        if (self.bubbleView.alpha != 1) {
            self.bubbleView.alpha = 1;
        }
    }
    
    if (messageLayout.messageModel.orderStatus == 3) {
        _stateLabel.text = @"Confirmed";
    } else if (messageLayout.messageModel.orderStatus == 4) {
        _stateLabel.text = @"Failed";
    } else {
        _stateLabel.text = @"Pending";
    }
}


@end
